<?php

declare(strict_types=1);

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

/**
 * 用户记录
 */
class UserDevice extends Model
{
    protected $table = 'user_device';
    protected $fillable = ['user_id', 'device_id', 'status'];

    const STATUS_OK = 1;
    const STATUS_FREEZE = 0;

    /**
     * 封禁账号相关的设备
     */
    static function freezeUserDevice($userId = 0)
    {
        if (empty($userId)) return false;
        if (!is_array($userId)) $userId = [$userId];
        return self::whereIn('user_id', $userId)->update(['status' => self::STATUS_FREEZE]);
    }

    /**
     * 解封账号相关的设备
     */
    static function unFreezeUserDevice($userId = 0)
    {
        return self::where('user_id', $userId)->update(['status' => self::STATUS_OK]);
    }
}
